package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.zzyl.entity.NursingProjectPlan;
import com.zzyl.mapper.NursingProjectMapper;
import com.zzyl.mapper.NursingProjectPlanMapper;
import com.zzyl.service.NursingProjectPlanService;
import com.zzyl.vo.NursingProjectPlanVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.stream.Collectors;


@Transactional
@Service
public class NursingProjectPlanServiceImpl implements NursingProjectPlanService {
    @Autowired
    private NursingProjectPlanMapper nursingProjectPlanMapper;

    @Autowired
    private NursingProjectMapper nursingProjectMapper;

    // 3.2 新增护理计划（包括护理项目，连NursingProjectPlan表。在查询NursingProject表）
    @Override
    public int insertBatch(List<NursingProjectPlanVo> projectPlanVoList) {
        List<NursingProjectPlan> projectPlanList = projectPlanVoList.stream().map(v -> BeanUtil.toBean(v, NursingProjectPlan.class)).collect(Collectors.toList());
        return nursingProjectPlanMapper.insertBatch(projectPlanList);
    }
    //3.6根据护理计划删除关联关系
    @Override
    public void deleteByNursingPlanId(Long nursingPlanId) {
        nursingProjectPlanMapper.deleteByNursingPlanId(nursingPlanId);
    }

    //3.5 修改护理计划时 护理计划项目表 受影响的行数
    @Override
    public int deleteByIds(List<Long> ids) {
        return nursingProjectPlanMapper.deleteByIds(ids);
    }
}
